<template>
	<view class="mainpadding beijingse">
		<view class="textcenter titletext">实付金额</view>
		<view class="margin_top textcenter">
			<text class="margin_right1 qian">￥{{lastmsg.pay_price}}</text>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="titletext">选择支付方式</view>
			<view class="flexbetween margin_top xiahuax" @click="changetype(10)">
				<view class="flexleft">
					<view class="weixin margin_right1"></view>
					<view class="notitletext">微信</view>
				</view>
				<view class="yigouxuan margin_right3" v-if="paytype!=10"></view>
				<view class="weigouxuan margin_right3" v-if="paytype==10"></view>
			</view>
			<view class="flexbetween margin_top xiahuax" @click="changetype(30)">
				<view class="flexleft">
					<view class="zhifub margin_right1"></view>
					<view class="notitletext">余额支付</view>
				</view>
				<view class="yigouxuan margin_right3" v-if="paytype!=30"></view>
				<view class="weigouxuan margin_right3" v-if="paytype==30"></view>
			</view>
			<view class="flexbetween margin_top">
				<view class="strongtext">积分抵扣
					<text class="huisetext">（积分剩余{{personInfo.score}}）</text>
				</view>
				<u-switch v-model="is_jfdk" activeColor="#228DFF"></u-switch>
			</view>
		</view>

		<!-- 固定底部 -->
		<view class="gudingdb">
			<view class="bigbtn" @click="atoncepay">确认支付</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				is_jfdk: true,
				paytype: 10, //10微信支付，30余额支付
				personInfo: {
					score: "",
				},
				lastmsg: {
					order_pay_no: "", //订单号
					pay_price: "" //支付金额
				},
				wxpay: {}
			}
		},
		onLoad(options) {
			this.lastmsg = JSON.parse(decodeURIComponent(options.msg));
			this.xianjin = this.lastmsg.pay_price
		},
		onShow() {
			this.init()
		},
		methods: {
			changetype(value) {
				this.paytype = value
			},
			init() {
				httpRequest.request('/api/user/index', 'POST', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.personInfo = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			atoncepay() {
				httpRequest.request('/api/order/payment', 'POST', {
					type: this.paytype,
					score_dk: this.is_jfdk ? 1 : 0,
					order_pay_no: this.lastmsg.order_pay_no
				}, false, false, true).then(res => {
					if (res.code == 1) {
						if (this.paytype == 10) {
							this.wxpay = res.data.wxconfig
							this.wxpayevent()
						} else {
							httpRequest.toast(res.msg);
							setTimeout(()=>{
								uni.redirectTo({
									url: "/pages/mypage/wodedingdan"
								})
							},500)
						}
					} else if(res.code == 2) {
						httpRequest.toast(res.msg);
						setTimeout(()=>{
							uni.redirectTo({
								url: "/pages/mypage/wodedingdan"
							})
						},500)
					}else{
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			wxpayevent() {
				let _this = this;
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: _this.wxpay.timeStamp,
					nonceStr: _this.wxpay.nonceStr,
					package: _this.wxpay.package,
					signType: _this.wxpay.signType,
					paySign: _this.wxpay.paySign,
					success: function(res) {
						// 支付成功
						uni.redirectTo({
							url: "/pages/mypage/wodedingdan"
						})
					},
					fail: function(err) {
						
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huisetext {
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.qian {
		font-size: 71rpx;
		font-family: DIN-Bold, DIN;
		font-weight: bold;
		color: #000000;
	}

	.jifen {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		// background-image: url('../../static/image/system/jf.png');
	}

	.yinhk {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		// background-image: url('../../static/image/system/yhk.png');
	}

	.fulijuan {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		// background-image: url('../../static/image/system/flj.png');
	}

	.weixin {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('@/static/images/system/weixin.png');
	}

	.zhifub {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('@/static/images/system/yue.png');
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
	}

	.daheitext {
		font-size: 36rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}
</style>
